import { createRouter, createWebHistory } from 'vue-router'
import type { RouteRecordRaw } from 'vue-router'
import { registerDynamicRoutes } from './dynamicRoutes'

const routes: RouteRecordRaw[] = [
  {
    path: '/',
    redirect: '/dashboard',
  },
  {
      path: '/cashier/beefgate',
      name: 'Beefgate',
      component: () => import('@/views/cashier/beefgate/index.vue'),
      props: true
  },
  {
    path: '/auth',
    children: [
      {
        path: 'login',
        name: 'Login',
        component: () => import('@/views/auth/login/index.vue'),
      },
      {
        path: 'register',
        name: 'Register',
        component: () => import('@/views/auth/register/index.vue'),
      },
    ],
  },
  {
    path: '/',
    name: 'MainLayout',
    component: () => import('@/layouts/pc/MainLayout.vue'),
    children: [
      {
        path: 'dashboard',
        name: 'Dashboard',
        component: () => import('@/views/dashboard/index.vue'),
      },

      {
        path: 'payment-config',
        name: 'PaymentConfig',
        meta: { title: '支付配置' },
        children: [
          {
            path: 'miaoma-cashappconfig',
            name: 'CashAppConfig',
            component: () => import('@/miaoma/cashappconfig/list.vue'),
            meta: { title: '收银应用配置' }
          },
          {
            path: 'miaoma-paychanneldict',
            name: 'PayChannelDict',
            component: () => import('@/miaoma/paychanneldict/list.vue'),
            meta: { title: '支付渠道字典' }
          },
          {
            path: 'miaoma-payproductdict',
            name: 'PayProductDict',
            component: () => import('@/miaoma/payproductdict/list.vue'),
            meta: { title: '支付产品字典' }
          },
          {
            path: 'miaoma-paydeviceqrcode',
            name: 'PayDeviceQrcode',
            component: () => import('@/miaoma/paydeviceqrcode/list.vue'),
            meta: { title: '聚合码牌' }
          },
          {
            path: 'miaoma-suantaiqrcode',
            name: 'SuantaiQrcode',
            component: () => import('@/miaoma/suantaiqrcode/list.vue'),
            meta: { title: '活码管理' }
          },
          {
            path: 'miaoma-paydeviceprinter',
            name: 'PayDevicePrinter',
            component: () => import('@/miaoma/paydeviceprinter/list.vue'),
            meta: { title: '云打印机' }
          },
          {
            path: 'miaoma-paydevicespeaker',
            name: 'PayDeviceSpeaker',
            component: () => import('@/miaoma/paydevicespeaker/list.vue'),
            meta: { title: '云喇叭' }
          },
          {
            path: 'miaoma-providerchannelconfig',
            name: 'ProviderChannelConfig',
            component: () => import('@/miaoma/providerchannelconfig/list.vue'),
            meta: { title: '服务商配置' }
          },
        ]
      },

      {
        path: 'system-settings',
        name: 'SystemSettings',
        children: [
          {
            path: 'overview',
            name: 'ConfigOverview',
            component: () => import('@/views/system-settings/overview/index.vue'),
            meta: { title: '配置概览' }
          },
          {
            path: 'basic',
            name: 'BasicSettings',
            component: () => import('@/views/system-settings/basic/index.vue'),
            meta: { title: '基本设置' }
          },
          {
            path: 'security',
            name: 'SecuritySettings',
            component: () => import('@/views/system-settings/security/index.vue'),
            meta: { title: '安全设置' }
          },
          {
            path: 'third-party',
            name: 'ThirdPartyConfig',
            component: () => import('@/views/system-settings/third-party/index.vue'),
            meta: { title: '第三方配置' },
            children: [
              {
                path: '',
                name: 'StorageSettings',
                component: () => import('@/views/system-settings/third-party/storage.vue'),
                meta: { title: '存储配置' }
              },
              {
                path: 'storage',
                name: 'StorageSettingsAlias',
                component: () => import('@/views/system-settings/third-party/storage.vue'),
                meta: { title: '存储配置' }
              },
              {
                path: 'sms',
                name: 'SmsSettings',
                component: () => import('@/views/system-settings/third-party/sms.vue'),
                meta: { title: '短信配置' }
              },
              {
                path: 'map',
                name: 'MapSettings',
                component: () => import('@/views/system-settings/third-party/map.vue'),
                meta: { title: '地图配置' }
              },
              {
                path: 'ocr',
                name: 'OcrSettings',
                component: () => import('@/views/system-settings/third-party/ocr.vue'),
                meta: { title: 'OCR配置' }
              }
            ]
          }
        ]
      },
      {
        path: 'profile',
        name: 'Profile',
        component: () => import('@/views/profile/index.vue'),
      },
      {
        path: 'merchant-management',
        name: 'MerchantManagement',
        meta: { title: '商户管理' },
        children: [
          {
            path: 'miaoma-merchant-info-list',
            name: 'MiaomaMerchantInfoList',
            component: () => import('@/miaoma/merchantinfo/list.vue'),
            meta: { title: '商户列表' }
          },
          {
            path: 'miaoma-merchant-store-list',
            name: 'MiaomaMerchantStoreList',
            component: () => import('@/miaoma/merchantstore/list.vue'),
            meta: { title: '商户门店列表2' }
          }
        ]
      },
      {
        path: 'merchant-onboarding',
        name: 'MerchantOnboarding',
        children: [
          {
            path: 'pre-onboarding',
            name: 'PreOnboarding',
            component: () => import('@/views/merchant-onboarding/pre-onboarding/index.vue'),
            meta: { title: '预进件' }
          },
          {
            path: 'channel-onboarding',
            name: 'ChannelOnboarding',
            component: () => import('@/views/merchant-onboarding/channel-onboarding/index.vue'),
            meta: { title: '渠道进件' }
          }
        ]
      },
      {
        path: 'order-management',
        name: 'OrderManagement',
        children: [
          {
              path: 'miaoma-pay-order',
              name: 'MiaomaPayOrder',
              component: () => import('@/miaoma/payorder/list.vue'),
              meta: { title: '支付订单管理' }
            },
            {
              path: 'miaoma-refund-order',
              name: 'MiaomaRefundOrder',
              component: () => import('@/miaoma/refundorder/list.vue'),
              meta: { title: '退款订单管理' }
            },
        ]
      },
      {
        path: 'transaction-notifications',
        name: 'TransactionNotifications',
        children: [
          {
            path: 'channel',
            name: 'ChannelNotifications',
            component: () => import('@/views/transaction-notifications/channel-notifications/index.vue'),
            meta: { title: '渠道通知' }
          },
          {
            path: 'merchant',
            name: 'MerchantCallbacks',
            component: () => import('@/views/transaction-notifications/merchant-callbacks/index.vue'),
            meta: { title: '商户回调' }
          }
        ]
      },
      {
        path: 'reconciliation',
        name: 'Reconciliation',
        children: [
          {
            path: 'channel',
            name: 'ChannelReconciliation',
            component: () => import('@/views/reconciliation/channel/index.vue'),
            meta: { title: '渠道对账' }
          },
          {
            path: 'merchant',
            name: 'MerchantReconciliation',
            component: () => import('@/views/reconciliation/merchant/index.vue'),
            meta: { title: '商户对账' }
          },
          {
            path: 'error-handling',
            name: 'ErrorHandling',
            component: () => import('@/views/reconciliation/error-handling/index.vue'),
            meta: { title: '差错处理' }
          },
          {
            path: 'files',
            name: 'ReconciliationFiles',
            component: () => import('@/views/reconciliation/files/index.vue'),
            meta: { title: '对账文件' }
          },
          {
            path: 'settlement',
            name: 'Settlement',
            component: () => import('@/views/reconciliation/settlement/index.vue'),
            meta: { title: '结算管理' }
          }
        ]
      },
      {
        path: 'data-statistics',
        name: 'DataStatistics',
        children: [
          {
            path: 'transaction',
            name: 'TransactionStatistics',
            component: () => import('@/views/data-statistics/transaction/index.vue'),
            meta: { title: '交易统计' }
          },
          {
            path: 'merchant',
            name: 'MerchantStatistics',
            component: () => import('@/views/data-statistics/merchant/index.vue'),
            meta: { title: '商户统计' }
          },
          {
            path: 'channel',
            name: 'ChannelStatistics',
            component: () => import('@/views/data-statistics/channel/index.vue'),
            meta: { title: '渠道统计' }
          },
          {
            path: 'revenue',
            name: 'RevenueStatistics',
            component: () => import('@/views/data-statistics/revenue/index.vue'),
            meta: { title: '收入统计' }
          },
          {
            path: 'trend',
            name: 'TrendAnalysis',
            component: () => import('@/views/data-statistics/trend/index.vue'),
            meta: { title: '趋势分析' }
          },
          {
            path: 'realtime',
            name: 'RealtimeMonitor',
            component: () => import('@/views/data-statistics/realtime/index.vue'),
            meta: { title: '实时监控' }
          }
        ]
      },
      {
        path: 'frontend-components',
        name: 'FrontendComponents',
        component: () => import('@/views/frontend-components/index.vue'),
        meta: { title: '前端组件' },
        children: [
          {
            path: '',
            name: 'ComponentsOverview',
            component: () => import('@/views/frontend-components/overview.vue'),
            meta: { title: '前端组件概览' }
          },
          {
            path: 'file-upload-demo',
            name: 'FileUploadDemo',
            component: () => import('@/views/frontend-components/file-upload-demo/index.vue'),
            meta: { title: '文件上传组件' },
            children: [
              {
                path: '',
                name: 'FileUploadExample',
                component: () => import('@/views/frontend-components/file-upload-demo/example.vue'),
                meta: { title: '基础示例' }
              },
              {
                path: 'simple',
                name: 'SimpleFileUploadExample',
                component: () => import('@/views/frontend-components/file-upload-demo/simple.vue'),
                meta: { title: '简洁组件示例' }
              }
            ]
          },
          {
            path: 'data-display-demo',
            name: 'DataDisplayDemo',
            component: () => import('@/views/frontend-components/data-display-demo/index.vue'),
            meta: { title: '数据展示组件' },
            children: [
              {
                path: '',
                name: 'StatisticsCardsExample',
                component: () => import('@/views/frontend-components/data-display-demo/statistics.vue'),
                meta: { title: '统计卡片' }
              },
              {
                path: 'table',
                name: 'DataTableExample',
                component: () => import('@/views/frontend-components/data-display-demo/table.vue'),
                meta: { title: '数据表格' }
              },
              {
                path: 'charts',
                name: 'DataChartsExample',
                component: () => import('@/views/frontend-components/data-display-demo/charts.vue'),
                meta: { title: '图表展示' }
              }
            ]
          },
          {
            path: 'form-demo',
            name: 'FormDemo',
            component: () => import('@/views/frontend-components/form-demo/index.vue'),
            meta: { title: '表单组件' },
            children: [
              {
                path: '',
                name: 'BasicFormExample',
                component: () => import('@/views/frontend-components/form-demo/basic.vue'),
                meta: { title: '基础表单' }
              },
              {
                path: 'advanced',
                name: 'AdvancedFormExample',
                component: () => import('@/views/frontend-components/form-demo/advanced.vue'),
                meta: { title: '高级表单' }
              },
              {
                path: 'validation',
                name: 'FormValidationExample',
                component: () => import('@/views/frontend-components/form-demo/validation.vue'),
                meta: { title: '表单验证' }
              }
            ]
          },
          {
            path: 'interaction-demo',
            name: 'InteractionDemo',
            component: () => import('@/views/frontend-components/interaction-demo/index.vue'),
            meta: { title: '交互组件' },
            children: [
              {
                path: '',
                name: 'ModalExample',
                component: () => import('@/views/frontend-components/interaction-demo/modal.vue'),
                meta: { title: '弹窗组件' }
              },
              {
                path: 'drawer',
                name: 'DrawerExample',
                component: () => import('@/views/frontend-components/interaction-demo/drawer.vue'),
                meta: { title: '抽屉组件' }
              },
              {
                path: 'notification',
                name: 'NotificationExample',
                component: () => import('@/views/frontend-components/interaction-demo/notification.vue'),
                meta: { title: '通知组件' }
              }
            ]
          }
        ]
      },
      {
        path: 'development-test',
        name: 'DevelopmentTest',
        meta: { title: '开发测试' },
        children: [
          {
            path: 'article',
            name: 'Article',
            component: () => import('@/miaoma/miaomaarticle/list.vue'),
            meta: { title: '文章管理' }
          },
          {
            path: 'merchant-management',
            name: 'MerchantList',
            component: () => import('@/views/development-test/merchant/merchant-management.vue'),
            meta: { title: '商户管理' }
          },
          {
            path: 'service-provider-management',
            name: 'ServiceProviderList',
            component: () => import('@/views/development-test/service-provider/service-provider-management.vue'),
            meta: { title: '服务商管理' }
          },
          {
            path: 'grade-protection',
            name: 'GradeProtection',
            component: () => import('@/views/grade-protection/index.vue'),
            meta: { title: '等级保护' }
          },
          {
            path: 'static-pay-code-test',
            name: 'staticPayCodeTest',
            component: () => import('@/views/StaticPayCodeTest.vue'),
            meta: { title: '静态聚合码测试' }
          },
          {
            path: 'dynamic-pay-code-test',
            name: 'dynamicPayCodeTest',
            component: () => import('@/views/dynamic.vue'),
            meta: { title: '动态聚合码测试' }
          },
          {
            path: 'pay-test',
            name: 'payTest',
            component: () => import('@/views/pay-test/index.vue'),
            meta: { title: '支付测试' }
          },
          {
            path: 'test-api',
            name: 'apiTest',
            component: () => import('@/views/ApiTest.vue'),
            meta: { title: 'API测试' }
          },
          {
            path: 'payment-channel-info',
            name: 'paymentChannelInfo',
            component: () => import('@/views/development-test/payment/channel-info.vue'),
            meta: { title: '支付渠道信息' }
          },

          {
            path: 'user-payment-test',
            name: 'userPaymentTest',
            component: () => import('@/views/development-test/payment/user-payment-test.vue'),
            meta: { title: '用户支付测试' }
          },
          {
            path: 'payment-context-display',
            name: 'paymentContextDisplay',
            component: () => import('@/views/development-test/payment/payment-context-display.vue'),
            meta: { title: '支付上下文展示' }
          },

          {
            path: 'appconfig-management',
            name: 'paymentAppConfig2',
            component: () => import('@/views/development-test/appconfig/appconfig-management.vue'),
            meta: { title: '支付应用配置管理V2' }
          },
          {
            path: 'api-test-suite',
            name: 'apiTestSuite',
            component: () => import('@/views/development-test/test/api-test-suite.vue'),
            meta: { title: 'API测试套件' }
          },
          {
            path: 'data-management-test',
            name: 'dataManagementTest',
            component: () => import('@/views/development-test/test/data-management-test.vue'),
            meta: { title: '数据管理测试' }
          },
          {
            path: 'system-tools-test',
            name: 'systemToolsTest',
            component: () => import('@/views/development-test/test/system-tools-test.vue'),
            meta: { title: '系统工具测试' }
          },
          {
            path: 'channel-management',
            name: 'channelManagement',
            component: () => import('@/views/development-test/channel/channel-management.vue'),
            meta: { title: '支付渠道管理' }
          },
          {
            path: 'product-management',
            name: 'productManagement',
            component: () => import('@/views/development-test/product/product-management.vue'),
            meta: { title: '支付产品管理' }
          },
          {
            path: 'qrcode-management',
            name: 'qrcodeManagement',
            component: () => import('@/views/development-test/qrcode/qrcode-management.vue'),
            meta: { title: '二维码管理' }
          },
          {
            path: 'qrcode-detail/:id',
            name: 'qrcodeDetail',
            component: () => import('@/views/development-test/qrcode/qrcode-detail.vue'),
            meta: { title: '聚合码牌详情' }
          },
          {
            path: 'qrcode-edit/:id',
            name: 'qrcodeEdit',
            component: () => import('@/views/development-test/qrcode/qrcode-edit.vue'),
            meta: { title: '聚合码牌编辑' }
          },
          {
            path: 'protocol3-management',
            name: 'Protocol3Management',
            component: () => import('@/views/development-test/protocol/protocol3-management.vue'),
            meta: { title: 'Protocol3 协议管理' }
          },
          {
            path: 'channel-protocol-mapping',
            name: 'ChannelProtocolMapping',
            component: () => import('@/views/development-test/channel/channel-protocol-mapping.vue'),
            meta: { title: '渠道协议关联管理' }
          },
          {
            path: 'chen-study',
            name: 'ChenStudy',
            component: () => import('@/views/development-test/study/chen-study.vue'),
            meta: { title: '陈先生学习', icon: 'BookOutlined' }
          },
        ]
      },
    ],
  },
  {
    path: '/pay',
    component: () => import('@/layouts/pay/PayLayout.vue'),
    children: [
      {
        path: '',
        name: 'pay',
        component: () => import('@/views/pay/index.vue'),
        props: true
      },
      {
        path: 'alipay',
        name: 'alipayPay',
        component: () => import('@/views/pay/alipay/index.vue'),
        props: true
      },
      {
        path: 'alipay/success',
        name: 'alipayPaySuccess',
        component: () => import('@/views/pay/alipay/success.vue')
      },
      {
        path: 'alipay/failed',
        name: 'alipayPayFailed',
        component: () => import('@/views/pay/alipay/fail.vue')
      },
      {
        path: 'alipay-isv',
        name: 'alipayIsvPay',
        component: () => import('@/views/pay/alipay-isv/index.vue'),
        props: true
      },
      {
        path: 'alipay-isv/success',
        name: 'alipayIsvPaySuccess',
        component: () => import('@/views/pay/alipay-isv/success.vue')
      },
      {
        path: 'alipay-isv/failed',
        name: 'alipayIsvPayFailed',
        component: () => import('@/views/pay/alipay-isv/fail.vue')
      },
      {
        path: 'wechat',
        name: 'wechatPay',
        component: () => import('@/views/pay/wechat/index.vue'),
        props: true
      },
      {
        path: 'wechat/success',
        name: 'wechatPaySuccess',
        component: () => import('@/views/pay/wechat/success.vue')
      },
      {
        path: 'wechat/failed',
        name: 'wechatPayFailed',
        component: () => import('@/views/pay/wechat/fail.vue')
      },
      {
        path: 'wechat/closed',
        name: 'wechatPayClosed',
        component: () => import('@/views/pay/wechat/close.vue')
      },
      {
        path: 'wechat-isv',
        name: 'wechatIsvPay',
        component: () => import('@/views/pay/wechat-isv/index.vue'),
        props: true
      },
      {
        path: 'wechat-isv/success',
        name: 'wechatIsvPaySuccess',
        component: () => import('@/views/pay/wechat-isv/success.vue')
      },
      {
        path: 'wechat-isv/failed',
        name: 'wechatIsvPayFailed',
        component: () => import('@/views/pay/wechat-isv/fail.vue')
      },
      {
        path: 'wechat-isv/closed',
        name: 'wechatIsvPayClosed',
        component: () => import('@/views/pay/wechat-isv/close.vue')
      },
      {
        path: 'leshua-alipay',
        component: () => import('@/views/pay/leshua-alipay/index.vue')
      },
      {
        path: 'leshua-alipay/success',
        component: () => import('@/views/pay/leshua-alipay/success.vue')
      },
      {
        path: 'leshua-alipay/fail',
        component: () => import('@/views/pay/leshua-alipay/fail.vue')
      },
      {
        path: 'leshua-wxpay',
        component: () => import('@/views/pay/leshua-wxpay/index.vue')
      },
      {
        path: 'leshua-wxpay/success',
        component: () => import('@/views/pay/leshua-wxpay/success.vue')
      },
      {
        path: 'leshua-wxpay/fail',
        component: () => import('@/views/pay/leshua-wxpay/fail.vue')
      }
    ]
  },
]

const router = createRouter({
  history: createWebHistory(),
  routes,
})

// 注册动态路由
registerDynamicRoutes(router)

export default router